<?php

namespace App;

use App\Http\Services\FileManager;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\SystemMedicine
 *
 * @property int $id
 * @property string $name 药品名称
 * @property string $upc 条形码
 * @property string $approval_number 批准文号
 * @property string $specification 规格
 * @property int $thumb_id 商品封面图
 * @property int $classify_id 药品分类：OTC甲乙、RX等
 * @property int $first_classify_id 药品一级分类id
 * @property int $second_classify_id 药品二级分类id
 * @property string $manufacturer 生产厂商名称
 * @property string $manufacturer_address 生产厂商地址
 * @property string $manufacturer_contact 生产厂商联系方式
 * @property string $electronic_regulatory_code 电子监管码
 * @property string|null $usage_and_dosage 用法用量
 * @property string|null $indications 适应症
 * @property string $adapt_to_the_crowd 适应人群
 * @property string $component 成分
 * @property string|null $adverse_reactions 不良反应
 * @property string|null $contraindications 禁忌
 * @property string|null $precautions 注意事项
 * @property string|null $interaction 药物相互作用
 * @property string|null $medication_for_children 儿童用药
 * @property string|null $medication_for_pregnancy_x_lactation 妊娠与哺乳用药
 * @property string|null $medication_for_aged 老年人用药
 * @property string $properties 性状
 * @property string $packing 包装
 * @property string $dosage_form 剂型
 * @property string $storage 贮藏
 * @property string|null $pharmacological_action 药理作用
 * @property string $expiry_date 有效期
 * @property string|null $detail 详情（富文本）
 * @property string|null $other_attribute_array 其他属性数组（json_encoded）
 * @property \Illuminate\Support\Carbon|null $deleted_at
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\SystemMedicine onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereAdaptToTheCrowd($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereAdverseReactions($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereApprovalNumber($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereClassifyId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereComponent($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereContraindications($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereDetail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereDosageForm($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereElectronicRegulatoryCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereExpiryDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereFirstClassifyId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereIndications($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereInteraction($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereManufacturer($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereManufacturerAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereManufacturerContact($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereMedicationForAged($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereMedicationForChildren($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereMedicationForPregnancyXLactation($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereOtherAttributeArray($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine wherePacking($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine wherePharmacologicalAction($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine wherePrecautions($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereProperties($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereSecondClassifyId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereSpecification($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereStorage($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereThumbId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereUpc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereUsageAndDosage($value)
 * @method static \Illuminate\Database\Query\Builder|\App\SystemMedicine withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\SystemMedicine withoutTrashed()
 * @mixin \Eloquent
 * @property int $status 状态 0：关闭 1：开启
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereStatus($value)
 * @property string $from 详情（富文本）
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereFrom($value)
 * @property string|null $simple_code 拼音简码
 * @property string|null $bit_code 本位码
 * @property string|null $nature_class 性质分类
 * @property string|null $use_class 用途分类
 * @property string|null $disease 主治疾病
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereBitCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereDisease($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereNatureClass($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereSimpleCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereUseClass($value)
 * @property string|null $drug_brand 商标
 * >>>>>>> d12c5da5527893a3202379e876cc860f1906629b
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereDrugBrand($value)
 * @property int $drug_type 药品分类：OTC甲乙、RX等
 * @method static \Illuminate\Database\Eloquent\Builder|\App\SystemMedicine whereDrugType($value)
 */
class SystemMedicine extends Model
{
    protected $table = "system_medicine";
    use SoftDeletes;
    protected $guarded=[];

    public static function getSystemMedicineImg($merchant_medicine_id){
        $merchantMedicineImg = SystemMedicineImg::whereSystemMedicineId($merchant_medicine_id)->first();
        if($merchantMedicineImg){
            $merchantMedicineImgUrl = FileManager::getImgUrl($merchantMedicineImg->img_id);
        }else{
            $merchantMedicineImgUrl = '';
        }

        return $merchantMedicineImgUrl;
    }

    public static function getSystemMedicineImgList($merchant_medicine_id){
        $merchantMedicineImg = SystemMedicineImg::whereSystemMedicineId($merchant_medicine_id)->get();
        if(count($merchantMedicineImg) > 0){
            foreach ($merchantMedicineImg as $val) {
                $val->img_Url = FileManager::getImgUrl($val->img_id);
            }
        }

        return $merchantMedicineImg;
    }

    /**
     * @param int $limit
     * @param int $offset
     * @return array
     */
    public static function getUpcArray($limit = 8000,$offset= 0){
        if ($limit == 0){
            $limit = 100000;
        }
        $data = self::whereStatus(1)
            ->offset($offset)
            ->limit($limit)
            ->pluck('upc')
            ->toArray();
        return $data;
    }
}
